package com.frogs.ucenter.v1.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frogs.framework.base.web.BaseController3;
import com.frogs.system.web.api.response.FailResponse;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.AppBaseException;
import com.frogs.ucenter.v1.request.UserAttentionRequestLogAddRequest;
import com.frogs.ucenter.v1.request.UserAttentionRequestLogListRequest;
import com.frogs.ucenter.v1.request.UserAttentionRequestLogUpdateRequest;
import com.frogs.ucenter.v1.service.UserAttentionRequestLogService;
import com.frogs.ucenter.v1.util.ApiConstants;

@Controller(ApiConstants.VERSION + "userAttentionRequestLogController")
@RequestMapping("/" + ApiConstants.VERSION )
public class UserAttentionRequestLogController extends BaseController3 {

	private static final String ROOT = "/user";

	private static final String USER_ATTENTION_REQUESTLOG_ADD = ROOT + "/attention/requestLog/add";
	private static final String USER_ATTENTION_REQUESTLOG_UPDATE = ROOT + "/attention/requestLog/update";
	private static final String USER_ATTENTION_REQUESTLOG_LIST = ROOT + "/attention/requestLog/list";
	
	@Resource(name=ApiConstants.VERSION+"userAttentionRequestLogService")
    private UserAttentionRequestLogService userAttentionRequestLogService;

	@RequestMapping(USER_ATTENTION_REQUESTLOG_ADD)
	public Response userAttentionRequestLogAdd(HttpServletRequest request){
		Response response = null;
		try {
			UserAttentionRequestLogAddRequest userAttentionRequestLogAdd = new UserAttentionRequestLogAddRequest();
			userAttentionRequestLogAdd.parse(request);
			response = userAttentionRequestLogService.add(userAttentionRequestLogAdd);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(USER_ATTENTION_REQUESTLOG_UPDATE)
	public Response userAttentionRequestLogUpdate(HttpServletRequest request){
		Response response = null;
		try {
			UserAttentionRequestLogUpdateRequest userAttentionRequestLogUpdate = new UserAttentionRequestLogUpdateRequest();
			userAttentionRequestLogUpdate.parse(request);
			response = userAttentionRequestLogService.update(userAttentionRequestLogUpdate);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(USER_ATTENTION_REQUESTLOG_LIST)
	public Response userAttentionRequestLogList(HttpServletRequest request){
		Response response = null;
		try {
			UserAttentionRequestLogListRequest userAttentionRequestLogList = new UserAttentionRequestLogListRequest();
			userAttentionRequestLogList.parse(request);
			response = userAttentionRequestLogService.getDetail(userAttentionRequestLogList);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
}